package com.logreview.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Locale;

public class ContextUtil implements ApplicationContextAware {
	private static ApplicationContext appContext = null;

	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
			appContext = arg0;
	}

	public static String getMessage(String code, Object[] params,
			String defaultDesc, Locale local) {
		return appContext.getMessage(code, params, defaultDesc, local);
	}

	public static <T> T getBean(String beanId, Class<T> clazz)
			throws BeansException {
		return appContext.getBean(beanId, clazz);
	}

	public static <T> T getBean(Class<T> clazz) throws BeansException {
		return appContext.getBean(clazz);
	}

	public static Object getBean(String beanId) throws BeansException {
		return appContext.getBean(beanId);
	}

}
